<template>
    <div
        class="ba-operate-form"
        :class="'ba-' + baTable.form.operate + '-form'"
        :style="'width: calc(100% - ' + baTable.form.labelWidth! / 2 + 'px)'"
    >
        <div style="text-align:right;margin-bottom: 20px;" v-if="baTable.form.operate=='edit'&&baTable.form.items">
            <el-button type="primary" @click="handleCopy" v-if="!isApprove">复制</el-button>
            <el-button type="primary" v-if="!isApprove&&(baTable.form.items!.statuss == '未发起'||baTable.form.items!.statuss == '已退回')" @click="handleTj">提交审批</el-button>
            <el-dropdown @command="handlePrint" v-if="gstype=='1'">
                <el-button type="primary" style="margin-left:10px">
                    打印单证<el-icon class="el-icon--right"><arrow-down /></el-icon>
                </el-button>
                <template #dropdown>
                    <el-dropdown-menu>
                    <el-dropdown-item command="17">简易版</el-dropdown-item>
                    <el-dropdown-item command="18">完整版</el-dropdown-item>
                    </el-dropdown-menu>
                </template>
            </el-dropdown>
        </div>
        <el-form
            v-if="!baTable.form.loading"
            ref="formRef"
            @keyup.enter="baTable.onSubmit(formRef)"
            :model="baTable.form.items"
            label-position="right"
            :label-width="'100px'"
            :rules="rules"
            :disabled="baTable.form.operate=='view'||isApprove"
        >
            <el-row>
                <el-col :span="12" class="half">
                    <FormItem :label="t('xBjhead.BJNO')" type="string" v-model="baTable.form.items!.BJNO" prop="BJNO" :input-attr="{ placeholder: '保存后自动生成' ,disabled:true}" />
                    <FormItem
                        :label="t('xBjhead.YWTYPE')"
                        type="select"
                        v-model="baTable.form.items!.YWTYPE"
                        prop="YWTYPE"
                        :data="{ content: { '出口': '出口', '进口': '进口', '内贸': '内贸' } }"
                        :input-attr="{ 
                            placeholder: t('Please select field', { field: t('xBjhead.YWTYPE') }),
                        }"
                    />
                    <FormItem :label="t('xBjhead.CORP')" 
                        v-model="baTable.form.items!.CORP" 
                        prop="CORP" 
                        type="remoteSelect"
                        :input-attr="{
                            pk: 'CORP',
                            field: 'CORP',
                            'remote-url': '/admin/corplib/index?type='+gstype,
                            onChange:getCurrentCorp
                        }"
                    />
                    <FormItem 
                        :label="t('xBjhead.CORPNAME')" 
                        type="string" 
                        v-model="baTable.form.items!.CORPNAME" 
                        prop="CORPNAME" 
                        :input-attr="{ 
                            placeholder: t('Please input field', { field: t('xBjhead.CORPNAME') }),
                            disabled:corpnameDisabled
                            }" />
                    <FormItem :label="t('xBjhead.CORPTELE')" type="string" v-model="baTable.form.items!.CORPTELE" prop="CORPTELE" :input-attr="{ placeholder: t('Please input field', { field: t('xBjhead.CORPTELE') }) }" />
                    <FormItem :label="t('xBjhead.CORPFAX')" type="string" v-model="baTable.form.items!.CORPFAX" prop="CORPFAX" :input-attr="{ placeholder: t('Please input field', { field: t('xBjhead.CORPFAX') }) }" />
                    <FormItem style="width:100%" :label="t('xBjhead.CORPADDR')" type="string" v-model="baTable.form.items!.CORPADDR" prop="CORPADDR" :input-attr="{ placeholder: t('Please input field', { field: t('xBjhead.CORPADDR') }) }" />
                    <FormItem style="width:100%" :label="t('xBjhead.CORPEMAIL')" type="string" v-model="baTable.form.items!.CORPEMAIL" prop="CORPEMAIL" :input-attr="{ placeholder: t('Please input field', { field: t('xBjhead.CORPEMAIL') }) }" />
                </el-col>
                <el-col :span="6">
                    <!-- 报价分类 -->
                    <FormItem 
                        :label="t('xBjhead.BJTYPE')" 
                        v-model="baTable.form.items!.BJTYPE" 
                        prop="BJTYPE" 
                        type="remoteSelect"
                        :input-attr="{
                            pk: 'code',
                            field: 'codename',
                            'remote-url': codelib  + 'now?where=bjtype'
                        }" 
                    />
                    <FormItem 
                        :label="t('xBjhead.SALES')" 
                        v-model="baTable.form.items!.SALES" 
                        prop="SALES" 
                        type="remoteSelect"
                        :input-attr="{
                            pk: 'nickname',
                            field: 'nickname',
                            'remote-url':authAdmin+'index',
                            placeholder: t('Click Select'),
                        }"
                    />
                    <FormItem 
                        :label="t('xBjhead.BJDATE')" 
                        type="datetime" 
                        v-model="baTable.form.items!.BJDATE" 
                        prop="BJDATE" 
                        :input-attr="{ 
                            placeholder: t('Please select field'),
                            onChange:bjDateChange
                            }" 
                    />
                    <FormItem :label="t('xBjhead.STARTDATE')" type="datetime" v-model="baTable.form.items!.STARTDATE" prop="STARTDATE" :input-attr="{ placeholder: t('Please select field') }" />
                    <FormItem :label="t('xBjhead.ENDDATE')" type="datetime" v-model="baTable.form.items!.ENDDATE" prop="ENDDATE" :input-attr="{ placeholder: t('Please select field') }" />
                    
                </el-col>
                <el-col :span="6">
                    <FormItem 
                    :label="t('xBjhead.CORPCONTACT')" 
                    v-model="baTable.form.items!.CORPCONTACT" 
                    prop="CORPCONTACT" 
                    type="remoteSelect"
                    :input-attr="{
                        pk: 'nickname',
                        field: 'nickname',
                        'remote-url':authAdmin+'index',
                        placeholder: t('Click Select'),
                    }"
                    />
                    <FormItem 
                        :label="t('xBjhead.CORPCOPYTO')" 
                        v-model="baTable.form.items!.CORPCOPYTO" 
                        prop="CORPCOPYTO" 
                        type="remoteSelect"
                        :input-attr="{
                            pk: 'nickname',
                            field: 'nickname',
                            'remote-url':authAdmin+'index',
                            placeholder: t('Click Select'),
                        }"
                    />
                    <FormItem
                        v-if="gstype==1"
                        :label="t('xBjhead.CZY')"
                        v-model="baTable.form.items!.CZY"
                        prop="CZY"
                        type="remoteSelect"
                        :input-attr="{
                            pk: 'nickname',
                            multiple:true,
                            field: 'nickname',
                            'remote-url':authAdmin+'index',
                            placeholder: t('Click Select')
                        }"
                    />

                </el-col>
            </el-row>
            <el-divider />
            <el-row>
                <el-col :span="12" class="half">
                    <el-form-item :label="t('xBjhead.GOODSID')" v-if="baTable.form.items!.CORP">
                        <el-select v-model="baTable.form.items!.GOODSID" 
                            @change="getCurrentGoods" 
                            :disabled="gstype=='2'">
                            <el-option
                            v-for="item in goodsList"
                            :key="item.GOODSID"
                            :label="item.GOODS"
                            :value="item.GOODSID"
                            />
                        </el-select>
                    </el-form-item>

                    <FormItem 
                        v-else
                        :label="t('xBjhead.GOODSID')" 
                        v-model="baTable.form.items!.GOODSID" 
                        prop="GOODSID" 
                        type="remoteSelect"
                        :input-attr="{
                            pk: 'GOODSID',
                            field: 'GOODS',
                            filterable:false,
                            'remote-url': goods  + 'index?search[]: {field:CORP,val:'+baTable.form.items!.CORP+',operator:'+'='+'}&order = GOODSID,desc',
                            onChange:getCurrentGoods,
                            disabled:gstype=='2'
                        }"
                    />
                    <FormItem :label="t('xBjhead.GOODS')" type="string" v-model="baTable.form.items!.GOODS" prop="GOODS" 
                    :input-attr="{ 
                        placeholder: t('Please input field', { field: t('xBjhead.GOODS') }),
                        disabled:goodsDisabled
                        }" 
                    />
                    <!-- <FormItem :label="t('xBjhead.TRANSLINE')" type="string" v-model="baTable.form.items!.TRANSLINE" prop="TRANSLINE" :input-attr="{ placeholder: t('Please input field', { field: t('xBjhead.TRANSLINE') }) }" /> -->
                    <!-- 起运地 -->
                    <el-form-item :label="t('xBjhead.TRANSLINE')" v-if="baTable.form.items!.YWTYPE=='内贸'" prop="TRANSLINE">
                        <el-select v-model="baTable.form.items!.TRANSLINE" placeholder="请选择" filterable style="width:100%">
                            <el-option v-for="item in regins.from" :label="item.remind" :value="item.remind" />
                        </el-select>
                    </el-form-item>
                    <el-form-item :label="t('xBjhead.TRANSLINE')" v-else prop="TRANSLINE">
                        <el-select v-model="baTable.form.items!.TRANSLINE" placeholder="请选择" filterable style="width:100%">
                            <el-option v-for="item in regins.from" :label="item.port" :value="item.port" />
                        </el-select>
                    </el-form-item>
                    <!-- 安装载重量  -->
                    <el-form-item :label="t('xBjhead.SAFEGWET')">
                        <div style="display:flex">
                            <el-input style="width:50%" v-model="baTable.form.items!.SAFEGWET" type="number"/>
                            -
                            <el-input style="width:50%" v-model="baTable.form.items!.SAFEGWETTO" type="number"/>
                        </div>
                    </el-form-item>
                    <!-- <FormItem  type="string" v-model="baTable.form.items!.SAFEGWET" prop="SAFEGWET" :input-attr="{ placeholder: t('Please input field', { field: t('xBjhead.SAFEGWET') }) }" /> -->
                    <!-- <FormItem :label="t('xBjhead.SAFEGWETTO')" type="string" v-model="baTable.form.items!.SAFEGWETTO" prop="SAFEGWETTO" :input-attr="{ placeholder: t('Please input field', { field: t('xBjhead.SAFEGWETTO') }) }" /> -->
                    <!-- 目的地 -->
                    <el-form-item :label="t('xBjhead.TRANSLINETO')" v-if="baTable.form.items!.YWTYPE=='内贸'" prop="TRANSLINETO">
                        <el-select v-model="baTable.form.items!.TRANSLINETO" placeholder="请选择" filterable style="width:100%">
                            <el-option v-for="item in regins.to" :label="item.remind" :value="item.remind" />
                        </el-select>
                    </el-form-item>
                    <el-form-item :label="t('xBjhead.TRANSLINETO')" v-else prop="TRANSLINETO">
                        <el-select v-model="baTable.form.items!.TRANSLINETO" placeholder="请选择" filterable style="width:100%">
                            <el-option v-for="item in regins.to" :label="item.port" :value="item.port" />
                        </el-select>
                    </el-form-item>
                    <!-- <FormItem 
                    :label="t('xBjhead.TRANSLINETO')" 
                    type="string" 
                    v-model="baTable.form.items!.TRANSLINETO" 
                    prop="TRANSLINETO" 
                    :input-attr="{ placeholder: t('Please input field', { field: t('xBjhead.TRANSLINETO') }) }" 
                    /> -->
                    <FormItem :label="t('xBjhead.MIDU')" type="string" v-model="baTable.form.items!.MIDU" prop="MIDU" :input-attr="{ placeholder: t('Please input field', { field: t('xBjhead.MIDU') })}" />
                    
                    <FormItem style="width:100%" :label="t('xBjhead.TANKDEMO')" type="string" v-model="baTable.form.items!.TANKDEMO" prop="TANKDEMO" :input-attr="{ placeholder: t('Please input field', { field: t('xBjhead.TANKDEMO') }) }" />
                </el-col>
                <el-col :span="6">
                    <FormItem :label="t('xBjhead.GOODSKIND')" type="string" v-model="baTable.form.items!.GOODSKIND" prop="GOODSKIND" :input-attr="{ placeholder: t('Please input field', { field: t('xBjhead.GOODSKIND') }) }" />
                    <FormItem 
                        :label="t('xBjhead.CONTYPE')" 
                        v-model="baTable.form.items!.CONTYPE" 
                        prop="CONTYPE" 
                        type="remoteSelect"
                        :input-attr="{
                            pk: 'box',
                            field: 'box',
                            'remote-url': '/admin/XBjhead/box',
                        }"
                    />
                    <FormItem 
                    :label="t('xBjhead.TANKTYPE')" 
                    v-model="baTable.form.items!.TANKTYPE" 
                    prop="TANKTYPE"
                    type="remoteSelect"
                        :input-attr="{
                            pk: 'code',
                            field: 'codename',
                            'remote-url': codelib  + 'now?where=potkind',
                        }"
                    />
                    <FormItem :label="t('xBjhead.TRANSDAYS')" type="string" v-model="baTable.form.items!.TRANSDAYS" prop="TRANSDAYS" :input-attr="{ placeholder: t('Please input field', { field: t('xBjhead.TRANSDAYS') }) }" />
                    
                </el-col>
                <el-col :span="6">
                    <FormItem :label="t('xBjhead.UNNO')" type="string" v-model="baTable.form.items!.UNNO" prop="UNNO" :input-attr="{ placeholder: t('Please input field', { field: t('xBjhead.UNNO') }) }" />
                    <FormItem 
                    :label="t('xBjhead.ALLTYPE')" 
                    v-if="gstype=='1'"
                    v-model="baTable.form.items!.ALLTYPE" 
                    prop="ALLTYPE" 
                    type="remoteSelect"
                        :input-attr="{
                            pk: 'code',
                            field: 'codename',
                            'remote-url': '/admin/XBjhead/cantype?id='+baTable.form.items!.GOODSID||'',
                        }"
                    />
                    <!-- <FormItem 
                    :label="t('xBjhead.ALLTYPE')" 
                    v-if="gstype=='2'"
                    v-model="baTable.form.items!.ALLTYPE" 
                    prop="ALLTYPE" 
                    type="remoteSelect"
                    :input-attr="{
                        pk: 'TCNO',
                        field: 'TCNO',
                        'remote-url': '/admin/XPot/index?search[]=%7B%22field%22:%22STATUS%22,%22val%22:%22SYZ%22,%22operator%22:%22%3D%22%7D',
                    }"
                    /> -->
                    <FormItem :label="t('xBjhead.ALLTYPE')" type="string" v-model="baTable.form.items!.ALLTYPE" prop="ALLTYPE" :input-attr="{ placeholder: t('Please input field', { field: t('xBjhead.ALLTYPE') }) }" />
                    <FormItem :label="t('xBjhead.TANKCBM')" type="string" v-model="baTable.form.items!.TANKCBM" prop="TANKCBM" :input-attr="{ placeholder: t('Please input field', { field: t('xBjhead.TANKCBM') }) }" />
                    <FormItem :label="t('xBjhead.FUELPRICE')" type="string" v-model="baTable.form.items!.FUELPRICE" prop="FUELPRICE" :input-attr="{ placeholder: t('Please input field', { field: t('xBjhead.FUELPRICE') }) }" />
                    
                </el-col>
            </el-row>
            <el-divider />
            <el-row>
                <el-col :span="12" class="half">
                    <!-- <FormItem 
                    :label="t('xBjhead.CONTRACTNO')" 
                    v-model="baTable.form.items!.CONTRACTNO" 
                    prop="CONTRACTNO" 
                    type="remoteSelect"
                        :input-attr="{
                            pk: 'code',
                            field: 'codename',
                            'remote-url':`/admin/xContract/index?search[]=%7B%22field%22:%22CORP%22,%22val%22:%22${baTable.form.items!.CORP}%22,%22operator%22:%22%3D%22%7D&search[]=%7B%22field%22:%22ACTIVE%22,%22val%22:%22${'1'}%22,%22operator%22:%22%3D%22%7D&type=1&order=id,desc`
                        }"
                    /> -->
                    <el-form-item :label="t('xBjhead.CONTRACTNO')" prop="CONTRACTNO">
                        <el-select v-model="baTable.form.items!.CONTRACTNO" placeholder="请选择" filterable style="width:100%">
                            <el-option v-for="item in contractList" :label="item" :value="item" />
                        </el-select>
                    </el-form-item>
                    <!-- 'remote-url': '/admin/tz/all?sql='+`select * from x_contract where active='1' and corp='${baTable.form.items!.CORP}'`, -->
                    <FormItem :label="t('xBjhead.PAYDAYS')" type="string" v-model="baTable.form.items!.PAYDAYS" prop="PAYDAYS" :input-attr="{ placeholder: t('Please input field', { field: t('xBjhead.PAYDAYS') }) }" />
                    <FormItem style="width:100%" :label="t('xBjhead.NOTE1')" type="textarea" v-model="baTable.form.items!.NOTE1" prop="NOTE1" :input-attr="{ rows: 3, placeholder: t('Please input field') }" @keyup.enter.stop="" @keyup.ctrl.enter="baTable.onSubmit(formRef)" />
                    
                </el-col>
                <el-col :span="12" class="half">
                    <FormItem :label="t('xBjhead.OP')" type="string" v-model="baTable.form.items!.OP" prop="OP" :input-attr="{ placeholder: '当前登录人',disabled:true }" />
                    <FormItem :label="t('xBjhead.OPTIME')" type="datetime" v-model="baTable.form.items!.OPTIME" prop="OPTIME" :input-attr="{ placeholder: '当前日期',disabled:true }" />
                    <FormItem style="width:100%" :label="t('xBjhead.NOTE2')" type="textarea" v-model="baTable.form.items!.NOTE2" prop="NOTE2" :input-attr="{ rows: 3, placeholder: t('Please input field') }" @keyup.enter.stop="" @keyup.ctrl.enter="baTable.onSubmit(formRef)" />
                </el-col>
            </el-row>
        <!-- <FormItem :label="t('xBjhead.CORPTYPE')" type="string" v-model="baTable.form.items!.CORPTYPE" prop="CORPTYPE" :input-attr="{ placeholder: t('Please input field', { field: t('xBjhead.CORPTYPE') }) }" />
        
        <FormItem :label="t('xBjhead.BJSTATUS')" type="radio" v-model="baTable.form.items!.BJSTATUS" prop="BJSTATUS" :data="{ content: { 1: t('xBjhead.BJSTATUS 1') } }" :input-attr="{ placeholder: t('Please select field', { field: t('xBjhead.BJSTATUS') }) }" />
        <FormItem :label="t('xBjhead.MFDS')" type="number" prop="MFDS" v-model.number="baTable.form.items!.MFDS" :input-attr="{ step: '1', placeholder: t('Please input field', { field: t('xBjhead.MFDS') }) }" />
        <FormItem :label="t('xBjhead.XHMFDS')" type="number" prop="XHMFDS" v-model.number="baTable.form.items!.XHMFDS" :input-attr="{ step: '1', placeholder: t('Please input field', { field: t('xBjhead.XHMFDS') }) }" />
        <FormItem :label="t('xBjhead.DSF')" type="number" prop="DSF" v-model.number="baTable.form.items!.DSF" :input-attr="{ step: '0.01', placeholder: t('Please input field', { field: t('xBjhead.DSF') }) }" />
        <FormItem :label="t('xBjhead.XHDSF')" type="number" prop="XHDSF" v-model.number="baTable.form.items!.XHDSF" :input-attr="{ step: '0.01', placeholder: t('Please input field', { field: t('xBjhead.XHDSF') }) }" />
        <FormItem :label="t('xBjhead.GYF')" type="number" prop="GYF" v-model.number="baTable.form.items!.GYF" :input-attr="{ step: '0.01', placeholder: t('Please input field', { field: t('xBjhead.GYF') }) }" />
        <FormItem :label="t('xBjhead.QYGMFYX')" type="number" prop="QYGMFYX" v-model.number="baTable.form.items!.QYGMFYX" :input-attr="{ step: '1', placeholder: t('Please input field', { field: t('xBjhead.QYGMFYX') }) }" />
        <FormItem :label="t('xBjhead.MDGMFYX')" type="number" prop="MDGMFYX" v-model.number="baTable.form.items!.MDGMFYX" :input-attr="{ step: '1', placeholder: t('Please input field', { field: t('xBjhead.MDGMFYX') }) }" />
        <FormItem :label="t('xBjhead.ZQF')" type="number" prop="ZQF" v-model.number="baTable.form.items!.ZQF" :input-attr="{ step: '0.01', placeholder: t('Please input field', { field: t('xBjhead.ZQF') }) }" />
        <FormItem :label="t('xBjhead.ZQFBZ')" type="string" v-model="baTable.form.items!.ZQFBZ" prop="ZQFBZ" :input-attr="{ placeholder: t('Please input field', { field: t('xBjhead.ZQFBZ') }) }" />
        <FormItem :label="t('xBjhead.QYGMFDC')" type="number" prop="QYGMFDC" v-model.number="baTable.form.items!.QYGMFDC" :input-attr="{ step: '1', placeholder: t('Please input field', { field: t('xBjhead.QYGMFDC') }) }" />
        <FormItem :label="t('xBjhead.MDGMFDC')" type="number" prop="MDGMFDC" v-model.number="baTable.form.items!.MDGMFDC" :input-attr="{ step: '1', placeholder: t('Please input field', { field: t('xBjhead.MDGMFDC') }) }" />
        <FormItem :label="t('xBjhead.QYGDCF')" type="number" prop="QYGDCF" v-model.number="baTable.form.items!.QYGDCF" :input-attr="{ step: '0.01', placeholder: t('Please input field', { field: t('xBjhead.QYGDCF') }) }" />
        <FormItem :label="t('xBjhead.QYGDCFBZ')" type="string" v-model="baTable.form.items!.QYGDCFBZ" prop="QYGDCFBZ" :input-attr="{ placeholder: t('Please input field', { field: t('xBjhead.QYGDCFBZ') }) }" />
        <FormItem :label="t('xBjhead.DCF')" type="number" prop="DCF" v-model.number="baTable.form.items!.DCF" :input-attr="{ step: '0.01', placeholder: t('Please input field', { field: t('xBjhead.DCF') }) }" />
        <FormItem :label="t('xBjhead.DCFBZ')" type="string" v-model="baTable.form.items!.DCFBZ" prop="DCFBZ" :input-attr="{ placeholder: t('Please input field', { field: t('xBjhead.DCFBZ') }) }" /> -->
        
        </el-form>
    </div>
</template>

<script setup lang="ts">
import { reactive, ref, inject, computed ,onMounted ,watchEffect} from 'vue'
import { useI18n } from 'vue-i18n'
import type baTableClass from '/@/utils/baTable'
import FormItem from '/@/components/formItem/index.vue'
import { ElForm, ElMessage, FormItemRule } from 'element-plus'
import { buildValidatorData } from '/@/utils/validate'
import { codelib ,corplib,goods,authAdmin} from '/@/api/controllerUrls'
import { getSelectData } from '/@/api/common'
import createAxios from '/@/utils/axios'
import { ArrowDown } from '@element-plus/icons-vue'
import { getFieldList } from '/@/api/backend/security/sensitiveData'

const formRef = ref<InstanceType<typeof ElForm>>()
const baTable = inject('baTable') as baTableClass

const { t } = useI18n()

const rules: Partial<Record<string, FormItemRule[]>> = reactive({
    GOODS: [buildValidatorData({name: 'required', title: t('xBjhead.GOODS')})],
    YWTYPE: [buildValidatorData({name: 'required', title: t('xBjhead.YWTYPE')})],
    SALES: [buildValidatorData({name: 'required', title: t('xBjhead.SALES')})],
    BJTYPE: [buildValidatorData({name: 'required', title: t('xBjhead.BJTYPE')})],
    CORPNAME: [buildValidatorData({name: 'required', title: t('xBjhead.CORPNAME')})],
    STARTDATE: [buildValidatorData({name: 'date', message: t('Please enter the correct field', { field: t('xBjhead.STARTDATE') })})],
    ENDDATE: [buildValidatorData({name: 'required', message: t('Please enter the correct field', { field: t('xBjhead.ENDDATE') })})],
    OPTIME: [buildValidatorData({name: 'date', message: t('Please enter the correct field', { field: t('xBjhead.OPTIME') })})],
})


const gstype = inject('gstype') 
const isApprove:any = inject('isApprove')

const doSave = (callback:any) => {
    baTable.form.items!.gstype = gstype
    baTable.form.items!.type = '1'
    baTable.onSubmit(formRef.value,callback)
}

defineExpose({
    doSave
})

onMounted(()=>{
    if(baTable.form.operate == 'add') getGoodsList()
})
watchEffect(()=>{
    if( baTable.form.operate && baTable.form.items!.CORP){
        getGoodsList()
    }
    if( baTable.form.items!.YWTYPE || baTable.form.items!.CORP){
        getRegins()
    }
})

const regins:{
    from:any[]
    to:any[]
} = reactive({
    from:[],
    to:[]
})

const getRegins = ()=>{
    if(baTable.form.items!.YWTYPE!=='内贸'){
        let sql = 'select port from port'
        createAxios({
            url: '/admin/tz/all?sql='+sql,
            method:'get'
        }).then((res:any)=>{
            regins.from = res.data
            regins.to = res.data
        })
    }else{
        let sqlFrom = `select remind from area where port='装货地' and corp='${baTable.form.items!.CORP}'`
        createAxios({
            url: '/admin/tz/all?sql='+sqlFrom,
            method:'get'
        }).then((res:any)=>{
            regins.from = res.data
        })
    
        let sqlTo = `select remind from area where port='送货地' and corp='${baTable.form.items!.CORP}'`
        createAxios({
            url: '/admin/tz/all?sql='+ sqlTo,
            method:'get'
        }).then((res:any)=>{
            regins.to = res.data
        })
    }

}


const corpnameDisabled = ref(false)
const contractList = ref([])
const getCurrentCorp = (name:string)=>{
    if(name){
        let url = corplib + 'index'
        corpnameDisabled.value = true
        getSelectData(url,name,{
            initValue:name
        }).then(res=>{
            let item = res.data.list[0] || {}
            baTable.form.items!.CORPNAME = item.CORPNAME

        })

        createAxios({
            url:'/admin/tz/all?sql='+`select * from x_contract where active='1' and corp='${name}' `,
            method:'get'
        }).then((res:any)=>{
            contractList.value = res.data
            res.data.length?baTable.form.items!.CONTRACTNO = '':baTable.form.items!.CONTRACTNO = '临时业务'
            console.log(res)
        })

    }else{
        corpnameDisabled.value = false
        baTable.form.items!.CORPNAME = ''
    }
}

onMounted(()=>{
    getGoodsList()
})

const goodsList:any = ref([])
const getGoodsList = ()=>{
    console.log(baTable.form.items!.CORP)
    let pms = ''
    if(baTable.form.items!.CORP){
        pms = '?CORP='+ baTable.form.items!.CORP
    }
    createAxios({
        url: goods +'index'+pms
    }).then(res=>{
        goodsList.value = res.data.list
    })
}

const goodsDisabled = ref(false)
const getCurrentGoods = (name:string)=>{
    if(name){
        let url = goods + 'index'
        goodsDisabled.value = true
        getSelectData(url,name,{
            initValue:name
        }).then(res=>{
            let item = res.data.list[0] || {}
            baTable.form.items!.GOODS = item.GOODS
            baTable.form.items!.GOODSKIND = item.GOODSKIND
            baTable.form.items!.UNNO = item.unno
            baTable.form.items!.MIDU = item.midu
            baTable.form.items!.ALLOWTYPE = item.ALLOWTYPE
            baTable.form.items!.TANKTYPE = item.TANKTYPE
            baTable.form.items!.TANKCBM = item.TANKCBM
    
            console.log(item)
        })
    }else{
        goodsDisabled.value = false
        baTable.form.items!.GOODS = ''
        baTable.form.items!.GOODSKIND = ''
        baTable.form.items!.UNNO = ''
        baTable.form.items!.MIDU = ''
        baTable.form.items!.ALLOWTYPE = ''
        baTable.form.items!.TANKTYPE = ''
        baTable.form.items!.TANKCBM = ''
    }
}

const bjDateChange = (val:any)=>{
    baTable.form.items!.STARTDATE = val
}

const handleCopy = ()=>{
    createAxios({
        url:'/admin/XBjhead/copy?bjno='+ baTable.form.items!.BJNO,
        method:'get'
    }).then((res:any)=>{
        getNewData(res.data)
        baTable.getIndex()
    })
}

const getNewData = (bjno:string)=>{
    createAxios({
        url:'admin/xBjhead/edit?BJNO='+bjno,
        method:'get'
    }).then((res:any)=>{
        baTable.form.items = res.data.row
        ElMessage.success('复制成功！')
    })
}

//维修核价里提交审批
const handleTj = ()=>{
    createAxios({
        url:'admin/XBjhead/tj',
        data:{
            ...baTable.form.items,
            bizno:baTable.form.items!.BIZNO
        },
        method:'post'
    }).then(()=>{
        ElMessage.success('提交成功')
        baTable.toggleForm()
        baTable.getIndex()
    })
}


const handlePrint = (type:string)=>{
    window.open(`/#/admin/print?type=${type}&tzid=${baTable.form.items!.BJNO}`)
}

</script>

<style scoped lang="scss">
.el-col.half{
    display: flex;
    flex-wrap: wrap;
    >div{
        width:50%;
    }
}
</style>
